package com.qianfeng.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qianfeng.bean.JsonResult;
import com.qianfeng.pojo.GoodsClass;
import com.qianfeng.pojo.UserTable;
import com.qianfeng.service.GoodsClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 *
 * @author DELL
 * @date 2021-9-22 16:16
 */
@RestController
@RequestMapping("goodsClass")
public class GoodsClassController {
    @Autowired
    private GoodsClassService goodsClassService;


    //查询数据
    @RequestMapping("findAllByPage")
    @ResponseBody
    public JsonResult findAllByPage(
            @RequestParam(value = "page",required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(value = "limit",required = false,defaultValue = "6") Integer pageSize){

        //设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        //查询所有用户
        List<GoodsClass> classAll = goodsClassService.selectAll();
        //封装到PageInfo对象中
        PageInfo<GoodsClass> PageInfo = new PageInfo<GoodsClass>(classAll);
        //返回JsonResult对象
        JsonResult jsonResult = JsonResult.ok();
        jsonResult.setCount(PageInfo.getTotal());
        jsonResult.setData(PageInfo.getList());

        return jsonResult;
    }
    @RequestMapping("deleteAll")
    @ResponseBody
    public String deleteAll(Integer [] ids){
        goodsClassService.deleteAll(ids);
        return "success";
    }
    @RequestMapping("deleteClassById")
    @ResponseBody
    public String deleteById(Integer id){
        goodsClassService.deleteById(id);
        return "success";
    }
    @RequestMapping("Add")
    @ResponseBody
    public String add(GoodsClass goodsClass){
        goodsClassService.add(goodsClass);
        return "success";
    }
    @RequestMapping("updateClass")
    @ResponseBody
    public String updateClass(GoodsClass goodsClass){
        System.err.println(goodsClass);
        goodsClassService.updateClass(goodsClass);
        return "success";
    }
}
